#include <string.h>

#include "UI.h"
#include "font.h"

int main(int argc, char **argv)
{
    int ret;
    ret = layer_init();
    if(ret < 0)
    {
        printf("layer_init fail\n");
        return -1;
    }
    
    struct rgb_info BG_rgb_picture;
    BG_rgb_picture.width = 1024;
    BG_rgb_picture.height= 600;
    load_rgb_file("/mnt/rgb/bg.rgb", &BG_rgb_picture);

    struct rgba_drawing_info wechat_drawing;
    wechat_drawing.rgba_obj.width = 200;
    wechat_drawing.rgba_obj.height = 200;
    wechat_drawing.dest_pos.left = 100;
    wechat_drawing.dest_pos.top = 360;
    wechat_drawing.dest_pos.width = 200;
    wechat_drawing.dest_pos.height = 200;
    load_rgba_file("/mnt/rgb/wechat.rgba", &wechat_drawing.rgba_obj);

    struct rgba_drawing_info voice_drawing;
    voice_drawing.rgba_obj.width = 200;
    voice_drawing.rgba_obj.height = 200;
    voice_drawing.dest_pos.left = 300;
    voice_drawing.dest_pos.top = 360;
    voice_drawing.dest_pos.width = 200;
    voice_drawing.dest_pos.height = 200;
    load_rgba_file("/mnt/rgb/voice.rgba", &voice_drawing.rgba_obj);

    struct rgba_drawing_info light_drawing;
    light_drawing.rgba_obj.width = 200;
    light_drawing.rgba_obj.height = 200;
    light_drawing.dest_pos.left = 500;
    light_drawing.dest_pos.top = 360;
    light_drawing.dest_pos.width = 200;
    light_drawing.dest_pos.height = 200;
    load_rgba_file("/mnt/rgb/light.rgba", &light_drawing.rgba_obj);

    struct rgba_drawing_info hand_drawing;
    hand_drawing.rgba_obj.width = 200;
    hand_drawing.rgba_obj.height = 200;
    hand_drawing.dest_pos.left = 700;
    hand_drawing.dest_pos.top = 360;
    hand_drawing.dest_pos.width = 200;
    hand_drawing.dest_pos.height = 200;
    load_rgba_file("/mnt/rgb/hand.rgba", &hand_drawing.rgba_obj);

    struct rgb_info Output_rgb;
    Output_rgb.width = 1024;
    Output_rgb.height = 600;
    int len = Output_rgb.width*Output_rgb.height*3;
    Output_rgb.rgb_buffer = ak_mem_dma_alloc(MODULE_ID_APP, len);
    
    struct RGB WhiteRGB = {250,250,224};

    StringOBJ strWechat;
    strWechat.string = "΢��";
    strWechat.height = 32;
    strWechat.stringPos.top = 560;
    strWechat.stringPos.left = 168;
    strWechat.fontRGB = WhiteRGB;

    StringOBJ strVoice;
    strVoice.string = "����ʶ��";
    strVoice.height = 32;
    strVoice.stringPos.top = 560;
    strVoice.stringPos.left = 336;
    strVoice.fontRGB = WhiteRGB;

    StringOBJ strLight;
    strLight.string = "�ƹ�";
    strLight.height = 32;
    strLight.stringPos.top = 560;
    strLight.stringPos.left = 568;
    strLight.fontRGB = WhiteRGB;

    StringOBJ strHand;
    strHand.string = "��������";
    strHand.height = 32;
    strHand.stringPos.top = 560;
    strHand.stringPos.left = 736;
    strHand.fontRGB = WhiteRGB;

    StringOBJ strTime;
    strTime.string = "23:22";
    strTime.height = 128;
    strTime.stringPos.top = 50;
    strTime.stringPos.left = 320;
    strTime.fontRGB = WhiteRGB;

    StringOBJ strData;
    strData.string = "����:7��2�� ������";
    strData.height = 32;
    strData.stringPos.top = 178;
    strData.stringPos.left = 320;
    strData.fontRGB = WhiteRGB;

    memcpy(Output_rgb.rgb_buffer, BG_rgb_picture.rgb_buffer, len);


    switchString2Mat(&strWechat);
    switchString2Mat(&strVoice);
    switchString2Mat(&strLight);
    switchString2Mat(&strHand);
    switchString2Mat(&strTime);
    switchString2Mat(&strData);

    inputRGBA2RGB(&wechat_drawing, &Output_rgb);
    inputRGBA2RGB(&voice_drawing, &Output_rgb);
    inputRGBA2RGB(&light_drawing, &Output_rgb);
    inputRGBA2RGB(&hand_drawing, &Output_rgb);

    inputStringObj(&strWechat, &Output_rgb);
    inputStringObj(&strVoice, &Output_rgb);
    inputStringObj(&strLight, &Output_rgb);
    inputStringObj(&strHand, &Output_rgb);
    inputStringObj(&strTime, &Output_rgb);
    inputStringObj(&strData, &Output_rgb);

    if(output_picture(&Output_rgb) < 0)
    {
        printf("output rgb_file fail\n");
        return -1;
    }
    return 0;
}